<template>
	<view class="page-service">
		<u-navbar :is-back="false" :border-bottom="true" title="三方服务" height="46" title-color="#333" :title-bold="true"
		 :title-size="36">
			<view class="navbar_wap">
				<view class="navbar-right">
					<u-icon name="search" color="#C40200" size="45" class="search_logo" @click="goSearch"></u-icon>
					<u-icon name="scan" color="#C40200" size="45" @click="scancode"></u-icon>
				</view>
			</view>
		</u-navbar>
		<view class="scroll-view-container">
			<!-- 左侧 -->
			<scroll-view class="left-scroll-view" scroll-y="true" :style="{height:wh+'rpx'}">
				<block v-for="(item,i) in cateList" :key="i">
					<view :class="['left-scroll-view-item',i===active?'active':'']" @click="activeChange(i)">{{item.name}}</view>
				</block>
			</scroll-view>
			<!-- 右侧 -->
			<scroll-view class="right-scroll-view" scroll-y="true" :scroll-top="scrollTop" :style="{height:wh+'rpx'}">
				<view class="server-head-img">
					<image src="/static/common/server-head.png" mode=""></image>
				</view>
				<view class="cate-lv2" v-for="(item2,i2) in catelLeve2" :key="i2" v-if="item2.children.length>0">
					<view class="cate-lv2-title">{{item2.name}}</view>
					<view class="cate-lv3-list">
						<view class="cate-lv3-item" v-for="(item3, i3) in item2.children" :key="i3" @click="goScreen(item3)">
							<image :src="`/static/server/${pinyin(item3.name)}.png`" mode=""></image>
							<text>{{item3.name}}</text> 
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import PinyinUtils from '@/utils/pingyinUtils.js'
	import { commonGet } from '@/api/commonapi.js'
	export default{
		data(){
			return{
				wh:0,
				active:0,
				cateAll:[],
				cateList:[],
				catelLeve2:[],
				scrollTop:0,
				$baseUrl:''
			}
		},
		computed:{
			
		},
	
		onLoad(){
			const sysInfo = uni.getSystemInfoSync()
			this.wh = sysInfo.windowHeight-50,
			this.getCateList()
			this.$baseUrl = this.baseUrl
		},
		
		methods:{
			getCateList(){
				const query = {
					ak:this.$store.state.token,
					cmd:'zCompany_list_proc',
					para:JSON.stringify({pagesize:10}),
				}
				commonGet(query,({Data}) => {
					this.cateAll = Data.Datas2.sort((a,b)=>{
						return a.orderby - b.orderby
					})
					this.cateList = this.cateAll.filter((item)=>{
						return item.pid == 0
					})
					this.catelLeve2 = this.cateAll.filter((item2)=>{
						item2.children = this.cateAll.filter((item3)=>{
							return item3.pid == item2.id
						})
						return item2.pid == this.cateList[this.active].id
					})
				})
			},
			
			activeChange(i){
				this.active = i;
				this.catelLeve2 = this.cateAll.filter((item2)=>{
					item2.children = this.cateAll.filter((item3)=>{
						return item3.pid == item2.id
					})
					return item2.pid == this.cateList[this.active].id
					
				})
				this.scrollTop = this.scrollTop === 0?1:0
			},
			goScreen(item){
				this.$u.route('/pages/service/Screen/screen', {
					zzcolid:this.cateList[this.active].id
				});
				// console.log(item.id+"是"+item.pid)
				// console.log(this.cateList[this.active].id)
			},
			scancode() {
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					}
				}); 
			},
			goSearch(){
				uni.navigateTo({
					url:"/pages/HomeLnner/search/search"
				})
			},
			pinyin(name){
				return PinyinUtils.chineseToPinYin(name)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page-service{
		background-color: #f7f7f7;
	}
	.navbar_wap {
		width: 100%;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		padding: 0 30rpx;
	
		.navbar-right {
			.search_logo {
				margin-right: 30rpx;
			}
		}
	}
	.search-box{
		position: sticky;
		top:0;
		z-index:999;
	}
	.scroll-view-container{
		display: flex;
		.left-scroll-view{
			width:202rpx;
			min-height: calc(100vh - 76px);
			height: 100%;
			background-color: #fff;
			.left-scroll-view-item{
				line-height: 102rpx;
				text-align: center;
				font-size: 26rpx;
				font-weight: bold;
			}
			.active{
				background-color: #f7f7f7;
				position: relative;
				color: #c40200;
			}
			.active::before{
				content:'';
				display:block;
				width:6rpx;
				height:102rpx;
				background-color: #C00000;
				position: absolute;
				top:50%;
				left: 0;
				transform: translateY(-50%);
			}
		}
		.right-scroll-view{
			width: 100%;
			padding: 22rpx 30rpx 0 28rpx;
			min-height: calc(100vh - 96px);
			background-color: #f7f7f7;
			.server-head-img{
				image{
					width: 100%;
					height: 174rpx;
					border-radius: 20rpx;
				}
			}
		}
	}
	.cate-lv2-title{
		font-size: 30rpx;
		font-weight: bold;
		text-align:left;
		padding:35rpx 0;
	}
	.cate-lv3-list{
		display: flex;
		flex-wrap: wrap;
		background-color: #fff;
		border-radius: 20rpx;
		padding:0rpx 0 30rpx 0;
		.cate-lv3-item{
			width: 33.33%;
			display: flex;
			flex-direction: column;
			justify-content: start;
			align-items: center;
			margin-top: 30rpx;
			image{
				width: 54rpx;
				height: 54rpx;
				margin-bottom: 14rpx;
			}
			text{
				font-size:22rpx;
			}
		}
	}
</style>
